﻿using Kingdee.BOS.Contracts;
using Kingdee.BOS;
using Kingdee.BOS.Contracts.Report;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Kingdee.BOS.App.Data;

namespace RCE.K3.YGJD.Business.PlugIn.PUR.Report
{
    [Description("采购入库退料明细表-报表")]
    [HotUpdate]
    public class PurInStockMRBReportEdit : SysReportBaseService
    {
        #region 重写

        /// <summary>
        /// 初始化
        /// </summary>
        public override void Initialize()
        {
            //初始化
            base.Initialize();

            // 简单账表类型：普通、树形、分页
            this.ReportProperty.ReportType = ReportType.REPORTTYPE_NORMAL;
            this.IsCreateTempTableByPlugin = false;

            //是否分组汇总
            this.ReportProperty.IsGroupSummary = true;
        }

        /// <summary>
        /// 获取过滤条件信息(构造单据信息)
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public override ReportTitles GetReportTitles(IRptParams filter)
        {
            ReportTitles reportTitles = new ReportTitles();
            DynamicObject customFilter = filter.FilterParameter.CustomFilter;
            if (customFilter != null)
            {
                string multiOrgnNameValues = this.GetMultiOrgnNameValues(customFilter["FOrgid"].ToString());
                string startValue = (customFilter["FStartDate"] == null) ? string.Empty : Convert.ToDateTime(customFilter["FStartDate"]).ToString("yyyy-MM-dd");
                string endValue = (customFilter["FEndDate"] == null) ? string.Empty : Convert.ToDateTime(customFilter["FEndDate"]).ToString("yyyy-MM-dd");
                string startCust = this.getBaseDataNumberValue(customFilter["FStartSupplier"] as DynamicObject);
                string endCust = this.getBaseDataNumberValue(customFilter["FEndSupplier"] as DynamicObject);
                string startItem = this.getBaseDataNumberValue(customFilter["FStartMaterialID"] as DynamicObject);
                string endItem = this.getBaseDataNumberValue(customFilter["FEndMaterialID"] as DynamicObject);
                reportTitles.AddTitle("FOrgid", multiOrgnNameValues);
                reportTitles.AddTitle("FDate", startValue + "至" + endValue);
                reportTitles.AddTitle("FSupplier", startCust + "至" + endCust);
                reportTitles.AddTitle("FMaterial", startItem + "至" + endItem);
            }
            return reportTitles;
        }

        /// <summary>
        /// 设置单据列
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public override ReportHeader GetReportHeaders(IRptParams filter)
        {
            ReportHeader header = new ReportHeader();
            // 编号
            header.AddChild("FBillTypeCN", new LocaleValue("单据类型", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FCreatorName", new LocaleValue("创建人", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FBILLNO", new LocaleValue("单据编号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FModifierName", new LocaleValue("最后修改人", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FDATE", new LocaleValue("日期", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FSupplierName", new LocaleValue("供应商名称", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FDocumentStatus", new LocaleValue("单据状态", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FDeptName", new LocaleValue("采购部门", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FPurchaserName", new LocaleValue("采购员", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FMaterialGroupName", new LocaleValue("物料分组", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FItemNumber", new LocaleValue("物料代码", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FItemName", new LocaleValue("物料名称", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FSPECIFICATION", new LocaleValue("规格型号", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FGSBM", new LocaleValue("归属事业部", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FStockUnitName", new LocaleValue("库存单位", this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            header.AddChild("FMUSTQTY", new LocaleValue("应收数量", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FREALQTY", new LocaleValue("实收数量", this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            header.AddChild("FINVOICEDQTY", new LocaleValue("开票数量", this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            header.AddChild("FTAXRATE", new LocaleValue("税率", this.Context.UserLocale.LCID), SqlStorageType.SqlDecimal);
            header.AddChild("FISFREE", new LocaleValue("是否赠品", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FTAXAMOUNT", new LocaleValue("税额", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FPRICE", new LocaleValue("单价", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FAMOUNT", new LocaleValue("金额", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FALLAMOUNT", new LocaleValue("价税合计", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FSettleTypeName", new LocaleValue("结算方式", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FPayConditionName", new LocaleValue("付款方式", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FISINCLUDEDTAX", new LocaleValue("是否含税", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FISPRICEEXCLUDETAX", new LocaleValue("价外税", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("F_UIXC_CPQX", new LocaleValue("产品去向", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            header.AddChild("FNOTE", new LocaleValue("备注", this.Context.UserLocale.LCID), SqlStorageType.Sqlvarchar);
            return header;
        }

        /// <summary>
        /// 创建临时报表
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="tableName"></param>
        public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName)
        {
            base.BuilderReportSqlAndTempTable(filter, tableName);
        }

        /// <summary>
        /// 设置汇总列信息
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public override List<SummaryField> GetSummaryColumnInfo(IRptParams filter)
        {
            var result = base.GetSummaryColumnInfo(filter);
            result.Add(new SummaryField("FREALQTY", Kingdee.BOS.Core.Enums.BOSEnums.Enu_SummaryType.SUM));
            result.Add(new SummaryField("FAMOUNT", Kingdee.BOS.Core.Enums.BOSEnums.Enu_SummaryType.SUM));
            result.Add(new SummaryField("FTAXAMOUNT", Kingdee.BOS.Core.Enums.BOSEnums.Enu_SummaryType.SUM));
            result.Add(new SummaryField("FALLAMOUNT", Kingdee.BOS.Core.Enums.BOSEnums.Enu_SummaryType.SUM));
            return result;
        }

        /// <summary>
        /// 构建order by语句
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        protected override string BuilderTempTableOrderBySQL(IRptParams filter)
        {
            //排序
            string datasort = Convert.ToString(filter.FilterParameter.SortString);
            string OrderBy;
            if (datasort != "")
            {
                OrderBy = datasort;
            }
            else
            {
                OrderBy = " FDate ";
            }
            return OrderBy;
        }

        /// <summary>
        /// 构建单据select 和字段
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        protected override string BuilderSelectFieldSQL(IRptParams filter)
        {
            string sqlstr = @"/*dialect*/select FBillTypeCN, FCreatorName,FBILLNO,FModifierName,FDATE,FSupplierName,FDocumentStatus,FDeptName,FPurchaserName,FMaterialGroupName
                               ,FItemNumber,FItemName,FSPECIFICATION,FGSBM,FStockUnitName,FMUSTQTY,FREALQTY,FINVOICEDQTY ,FTAXRATE,FISFREE,FTAXAMOUNT
                                ,FPRICE,FAMOUNT,FALLAMOUNT,FSettleTypeName,FPayConditionName,FISINCLUDEDTAX,FISPRICEEXCLUDETAX,F_UIXC_CPQX,FNOTE";
            return sqlstr;
        }


        /// <summary>
        /// 构建from where语句
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        protected override string BuilderFromWhereSQL(IRptParams filter)
        {
            DynamicObject customFilter = filter.FilterParameter.CustomFilter;
            StringBuilder strwhere = new StringBuilder();

            string startDate = (customFilter["FStartDate"] == null)
                ? DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")
                : Convert.ToDateTime(customFilter["FStartDate"]).ToString("yyyy-MM-dd");
            string endDate = (customFilter["FEndDate"] == null)
                ? DateTime.Now.ToString("yyyy-MM-dd")
                : Convert.ToDateTime(customFilter["FEndDate"]).ToString("yyyy-MM-dd");

            strwhere.AppendLine(string.Format(@" from 
                                (select billtypel.FNAME FBillTypeCN, suc.FNAME FCreatorName, sis.FBILLNO, sumo.FNAME FModifierName,
	convert(varchar(200),sis.FDATE,23) FDATE,sup.FNumber FSupplierNumber,
	supl.FNAME FSupplierName, docstatus.fname FDocumentStatus,deptl.FNAME FDeptName,buyerl.FNAME  FPurchaserName,
	bmgl.FNAME FMaterialGroupName,item.FNUMBER FItemNumber, iteml.FNAME FItemName,iteml.FSPECIFICATION,gsbml.FNAME FGSBM,
	unitl.FNAME FStockUnitName,FMUSTQTY,
	FREALQTY,sisef.FINVOICEDQTY,sisef.FTAXRATE ,case when sisef.FISFREE = 1 then '是' else '否' end FISFREE,
	sisef.FTAXAMOUNT,sisef.FPRICE,sisef.FAMOUNT,sisef.FALLAMOUNT,settypel.FNAME FSettleTypeName,
	paycl.FNAME FPayConditionName,case when sisf.FISINCLUDEDTAX  = 1 then '是' else '否' end FISINCLUDEDTAX,
	case when sisf.FISPRICEEXCLUDETAX  = 1 then '是' else '否' end FISPRICEEXCLUDETAX, sise.F_UIXC_CPQX F_UIXC_CPQX,
	sise.FNOTE,purorg.FNUMBER FPurOrgNumber, '采购入库单' FBillTypeNo,cast(bmg.FID as varchar(200)) FMATERIALGROUPID,purorg.FORGID FPurOrgID
from t_STK_InStock sis with(nolock)
left join t_STK_InStockFin sisf with(nolock) on sisf.FID = sis.FID
left join T_STK_INSTOCKENTRY sise with(nolock) on sise.FID = sis.FID
left join T_STK_INSTOCKENTRY_F sisef with(nolock) on sisef.FENTRYID = sise.FENTRYID
left join T_BAS_BILLTYPE_L billtypel with(nolock) on billtypel.FBILLTYPEID = sis.FBILLTYPEID and billtypel.FLOCALEID = 2052
left join T_SEC_USER suc with(nolock) on suc.FUSERID = sis.FCREATORID
left join T_SEC_USER sumo with(nolock) on sumo.FUSERID = sis.FMODIFIERID
left join T_BD_SUPPLIER sup with(nolock) on sup.FSUPPLIERID = sis.FSUPPLIERID
left join T_BD_SUPPLIER_L supl with(nolock) on supl.FSUPPLIERID = sis.FSUPPLIERID and supl.FLOCALEID = 2052
left join v_statusname docstatus with(nolock) on docstatus.fvalue =sis.FDOCUMENTSTATUS
left join T_BD_DEPARTMENT_l deptl with(nolock) on deptl.FDEPTID = sis.FPURCHASEDEPTID and deptl.FLOCALEID = 2052
left join V_BD_BUYER_L buyerl with(nolock) on buyerl.fid = sis.FPURCHASERID and buyerl.FLOCALEID = 2052 
left join T_BD_MATERIAL item with(nolock) on item.FMATERIALID = sise.FMATERIALID
left join T_BD_MATERIAL_L iteml with(nolock) on iteml.FMATERIALID = item.FMATERIALID and iteml.FLOCALEID = 2052
left join T_BD_MATERIALSTOCK mstock with(nolock) on mstock.FMATERIALID = item.FMATERIALID
left join T_BD_UNIT_L unitl with(nolock) on unitl.FUNITID = mstock.FSTOREUNITID and unitl.FLOCALEID = 2052
left join T_BD_PAYMENTCONDITION_l paycl with(nolock) on paycl.FID = sisf.FPAYCONDITIONID and paycl.FLOCALEID = 2052
left join T_BD_SETTLETYPE_l settypel with(nolock) on settypel.FID = sisf.FSETTLETYPEID and settypel.FLOCALEID = 2052
left join T_BD_MATERIALGROUP bmg with(nolock) on bmg.FID = item.FMaterialGroup
left join T_BD_MATERIALGROUP_L bmgl with(nolock) on bmgl.FID = bmg.FID and bmgl.FLOCALEID= 2052
left join T_BD_DEPARTMENT_L gsbml with(nolock) on gsbml.FDEPTID = item.F_UIXC_GSSYB and gsbml.FLOCALEID = 2052
left join T_ORG_ORGANIZATIONS purorg with(nolock) on purorg.FORGID = sis.FPURCHASEORGID
where sis.FDATE >= '{0}' and sis.FDATE <= '{1}'
union all
select billtypel.FNAME FBillType, suc.FNAME FCreatorName, sis.FBILLNO, sumo.FNAME FModifierName,
	convert(varchar(200),sis.FDATE,23) FDATE,sup.FNumber FSupplierNumber,
	supl.FNAME FSupplierName, docstatus.fname FDocumentStatus,deptl.FNAME FDeptName,buyerl.FNAME  FPurchaserName,
	bmgl.FNAME FMaterialGroupName,item.FNUMBER FItemNumber, iteml.FNAME FItemName,iteml.FSPECIFICATION, gsbml.FNAME FGSBM,
	unitl.FNAME FStockUnitName,-FRMREALQTY FRMREALQTY,
	-FRMREALQTY FRMREALQTY,-sisef.FINVOICEDQTY FINVOICEDQTY,sisef.FTAXRATE , '否' FISFREE,
	-sisef.FTAXAMOUNT FTAXAMOUNT,sisef.FPRICE,-sisef.FAMOUNT FAMOUNT,-sisef.FALLAMOUNT FALLAMOUNT,settypel.FNAME FSettleTypeName,
	paycl.FNAME FPayConditionName,case when sisf.FISINCLUDEDTAX  = 1 then '是' else '否' end FISINCLUDEDTAX,
	case when sisf.FISPRICEEXCLUDETAX  = 1 then '是' else '否' end FISPRICEEXCLUDETAX, '' F_UIXC_CPQX,
	sise.FNOTE,purorg.FNUMBER FPurOrgNumber, '采购退料单' FBillTypeNo, cast(bmg.FID as varchar(200)) FMATERIALGROUPID,purorg.FORGID FPurOrgID
from t_PUR_MRB sis with(nolock)
left join T_PUR_MRBFIN sisf with(nolock) on sisf.FID = sis.FID
left join T_PUR_MRBENTRY sise with(nolock) on sise.FID = sis.FID
left join T_PUR_MRBENTRY_F sisef with(nolock) on sisef.FENTRYID = sise.FENTRYID
left join T_BAS_BILLTYPE_L billtypel with(nolock) on billtypel.FBILLTYPEID = sis.FBILLTYPEID and billtypel.FLOCALEID = 2052
left join T_SEC_USER suc with(nolock) on suc.FUSERID = sis.FCREATORID
left join T_SEC_USER sumo with(nolock) on sumo.FUSERID = sis.FMODIFIERID
left join T_BD_SUPPLIER sup with(nolock) on sup.FSUPPLIERID = sis.FSUPPLIERID
left join T_BD_SUPPLIER_L supl with(nolock) on supl.FSUPPLIERID = sis.FSUPPLIERID and supl.FLOCALEID = 2052
left join v_statusname docstatus with(nolock) on docstatus.fvalue =sis.FDOCUMENTSTATUS
left join T_BD_DEPARTMENT_l deptl with(nolock) on deptl.FDEPTID = sis.FPURCHASEDEPTID and deptl.FLOCALEID = 2052
left join V_BD_BUYER_L buyerl with(nolock) on buyerl.fid = sis.FPURCHASERID and buyerl.FLOCALEID = 2052 
left join T_BD_MATERIAL item with(nolock) on item.FMATERIALID = sise.FMATERIALID
left join T_BD_MATERIAL_L iteml with(nolock) on iteml.FMATERIALID = item.FMATERIALID and iteml.FLOCALEID = 2052
left join T_BD_MATERIALSTOCK mstock with(nolock) on mstock.FMATERIALID = item.FMATERIALID
left join T_BD_UNIT_L unitl with(nolock) on unitl.FUNITID = mstock.FSTOREUNITID and unitl.FLOCALEID = 2052
left join T_BD_PAYMENTCONDITION_l paycl with(nolock) on paycl.FID = sisf.FPAYCONDITIONID and paycl.FLOCALEID = 2052
left join T_BD_SETTLETYPE_l settypel with(nolock) on settypel.FID = sisf.FSETTLETYPEID and settypel.FLOCALEID = 2052
left join T_BD_MATERIALGROUP bmg with(nolock) on bmg.FID = item.FMaterialGroup
left join T_BD_MATERIALGROUP_L bmgl with(nolock) on bmgl.FID = bmg.FID and bmgl.FLOCALEID= 2052
left join T_BD_DEPARTMENT_L gsbml with(nolock) on gsbml.FDEPTID = item.F_UIXC_GSSYB and gsbml.FLOCALEID = 2052
left join T_ORG_ORGANIZATIONS purorg with(nolock) on purorg.FORGID = sis.FPURCHASEORGID
where sis.FDATE >= '{0}' and sis.FDATE <= '{1}'

) t1  Where 1=1 ", startDate, endDate));

            #region 组织，日期，单据类型
            //组织
            string org = string.IsNullOrWhiteSpace(customFilter["FOrgid"].ToString())
                ? " " : string.Format(" AND FPurOrgID IN ({0}) ", Convert.ToString(customFilter["FOrgid"]));
            strwhere.AppendLine(org);

            // 单据类型
            string billType = string.IsNullOrWhiteSpace(customFilter["FBillType"].ToString())
                ? " " : string.Format(" and FBillTypeNo in ({0})", $"'{customFilter["FBillType"].ToString().Replace(",", "','")}'");

            strwhere.AppendLine(billType);

            //日期
            strwhere.AppendLine(string.Format(" AND FDate>='{0}' and FDate<='{1}' ", startDate, endDate));

            #endregion

            #region 供应商
            string startCust = this.getBaseDataNumberValue(customFilter["FStartSupplier"] as DynamicObject);
            if (!string.IsNullOrWhiteSpace(startCust))
            {
                strwhere.AppendLine($" and FSupplierNumber >= '{startCust}'");
            }
            string endCust = this.getBaseDataNumberValue(customFilter["FEndSupplier"] as DynamicObject);
            if (!string.IsNullOrWhiteSpace(endCust))
            {
                strwhere.AppendLine($" and FSupplierNumber <= '{endCust}'");
            }
            #endregion

            #region 物料
            string startItem = this.getBaseDataNumberValue(customFilter["FStartMaterialID"] as DynamicObject);
            if (!string.IsNullOrWhiteSpace(startItem))
            {
                strwhere.AppendLine($" and FItemNumber <= '{startItem}'");
            }
            string endItem = this.getBaseDataNumberValue(customFilter["FEndMaterialID"] as DynamicObject);
            if (!string.IsNullOrWhiteSpace(endItem))
            {
                strwhere.AppendLine($" and FItemNumber >= '{endItem}'");
            }
            #endregion

            #region 单据编号
            string F_QAAW_SBillNo = customFilter["FStartBillNo"] == null ? "" : customFilter["FStartBillNo"].ToString();
            if (!string.IsNullOrWhiteSpace(F_QAAW_SBillNo))
            {
                strwhere.AppendLine($" and FBILLNO <= '{F_QAAW_SBillNo}'");
            }
            string F_QAAW_EBillNo = customFilter["FEndBillNo"] == null ? "" : customFilter["FEndBillNo"].ToString();
            if (!string.IsNullOrWhiteSpace(F_QAAW_EBillNo))
            {
                strwhere.AppendLine($" and FBILLNO >= '{F_QAAW_EBillNo}'");
            }
            #endregion

            string FSMaterialGroup = this.getBaseDataNumberValue(customFilter["FStartMaterialGroup"] as DynamicObject);
            string FEMaterialGroup = this.getBaseDataNumberValue(customFilter["FEndMaterialGroup"] as DynamicObject);
            strwhere.AppendLine(getFilterMaterialGroup(FSMaterialGroup, FEMaterialGroup));

            if (!string.IsNullOrWhiteSpace(filter.FilterParameter.FilterString))
            {
                strwhere.AppendLine(" and " + filter.FilterParameter.FilterString);
            }

            string execSql = strwhere.ToString();
            return execSql;
        }


        #endregion

        #region 公共方法

        /// <summary>
        /// 物料分组编码
        /// </summary>
        /// <param name="FSMaterialGroup"></param>
        /// <param name="FEMaterialGroup"></param>
        /// <returns></returns>
        public string getFilterMaterialGroup(string FSMaterialGroup, string FEMaterialGroup)
        {
            HashSet<string> setGroup = new HashSet<string>();
            if (!string.IsNullOrWhiteSpace(FSMaterialGroup) || !string.IsNullOrWhiteSpace(FEMaterialGroup))
            {
                string sql = "select FID from T_BD_MATERIALGROUP where  1=1  ";
                if (!string.IsNullOrWhiteSpace(FSMaterialGroup))
                {
                    sql += $" and FNUMBER >='{FSMaterialGroup}' ";
                }

                if (!string.IsNullOrWhiteSpace(FEMaterialGroup))
                {
                    sql += $" and FNUMBER <='{FEMaterialGroup}' ";
                }
                DynamicObjectCollection mGroup = DBUtils.ExecuteDynamicObject(Context, sql);
                if (mGroup != null)
                {
                    foreach (var item in mGroup)
                    {
                        string sql1 = $"select FID from T_BD_MATERIALGROUP where fid = {item["FID"].ToString()} or FFULLPARENTID like '%{item["FID"].ToString()}%'";
                        DynamicObjectCollection CmGroup = DBUtils.ExecuteDynamicObject(Context, sql);
                        foreach (var item1 in CmGroup)
                        {
                            setGroup.Add(item1["FID"].ToString());
                        }
                    }
                }
            }
            string strMapGroup = "'0'";
            foreach (var item in setGroup)
            {
                strMapGroup += $",'{item}'";
            }
            if (setGroup.Count > 0)
            {
                return $" and FMATERIALGROUPID in ({strMapGroup})";
            }
            return "";
        }

        /// <summary>
        /// 组织名称
        /// </summary>
        /// <param name="orgIdStrings"></param>
        /// <returns></returns>
        private string GetMultiOrgnNameValues(string orgIdStrings)
        {
            List<string> list = new List<string>();
            string result = string.Empty;
            if (orgIdStrings.Trim().Length > 0)
            {
                IQueryService service = Kingdee.BOS.Contracts.ServiceFactory.GetService<IQueryService>(base.Context);
                QueryBuilderParemeter para = new QueryBuilderParemeter
                {
                    FormId = "ORG_Organizations",
                    SelectItems = SelectorItemInfo.CreateItems("FNAME"),
                    FilterClauseWihtKey = string.Format(" FORGID IN ({0}) AND FLOCALEID={1}", orgIdStrings, base.Context.UserLocale.LCID)
                };
                DynamicObjectCollection dynamicObjectCollection = service.GetDynamicObjectCollection(base.Context, para, null);
                foreach (DynamicObject current in dynamicObjectCollection)
                {
                    list.Add(current["FNAME"].ToString());
                }
                if (list.Count > 0)
                {
                    result = string.Join(",", list.ToArray());
                }
            }
            return result;
        }

        /// <summary>
        /// 基础资料名称
        /// </summary>
        /// <param name="dyobj"></param>
        /// <returns></returns>
        private string GetBaseDataNameValue(DynamicObjectCollection dyobj)
        {
            string name = "";
            foreach (DynamicObject dynbj in dyobj)
            {
                if (dynbj != null || !dynbj.DynamicObjectType.Properties.Contains("Name"))
                {
                    DynamicObject dynbj2 = (DynamicObject)dynbj[2];
                    name = name + ",'" + dynbj2["Name"].ToString() + "'";
                }
            }
            if (name.Length > 0)
            {
                name = name.Substring(1, name.Length - 1);
            }
            return name;
        }

        /// <summary>
        /// 获取 基础资料 编码
        /// </summary>
        /// <param name="dyobj"></param>
        /// <returns></returns>
        public string getBaseDataNumberValue(DynamicObject dyobj)
        {
            if (dyobj == null)
            {
                return "";
            }
            string number = "";
            if (dyobj.DynamicObjectType.Properties.Contains("Number"))
            {
                number = dyobj["Number"].ToString();
            }
            return number;
        }

        #endregion

    }
}
